package manager.qrcode;


import java.util.HashMap;
import java.util.Map;



import com.github.wxpay.sdk.WXPay;


import database.pojo.UserRechargeInfo;

import util.WXConfig;

public class WXQrcode {
	private static WXConfig config = new WXConfig();
	private static WXPay wxpay = new WXPay(config);

		           
	public String getWXQrcode(UserRechargeInfo uInfo, String notifyUrl,int consumptionType) {
		//System.out.println("getWXQrcode:");
		Map<String, String> data = new HashMap<String, String>();
		int money =(int) uInfo.getMount()*100;
        data.put("body", "乐音坊套餐购买");
        data.put("out_trade_no", uInfo.getRecharge_orderid());
        data.put("device_info", Integer.toString(uInfo.getMid()));
        data.put("fee_type", "CNY");
        //data.put("total_fee", Integer.toString(money));//单位为分
        data.put("total_fee", "1");//测试
        data.put("notify_url", notifyUrl);
        data.put("trade_type", "NATIVE");  // 此处指定为扫码支付
        data.put("product_id", Integer.toString(uInfo.getPacketId()));
        data.put("attach", Integer.toString(consumptionType));

        try {
            Map<String, String> resp = wxpay.unifiedOrder(data);
            System.out.println(resp.get("code_url"));
            return resp.get("code_url");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
	}
	
	public boolean SignaTure(Map<String, String> notifyMap) throws Exception {
		if(notifyMap==null) {
			return false;
		}
		if (wxpay.isPayResultNotifySignatureValid(notifyMap)) {
            return true;
        }
        else {
            return false;
        }
		
	}

     
}
